package com.xyw.his00.controller;

import com.xyw.his00.anno.OptionLog;
import com.xyw.his00.dto.CheckRequestDTO;
import com.xyw.his00.dto.DisposalRequestDTO;
import com.xyw.his00.entity.ResponseData;
import com.xyw.his00.mapper.DisposalRequestMapper;
import com.xyw.his00.pojo.dbpojo.CheckRequest;
import com.xyw.his00.pojo.dbpojo.DisposalRequest;
import com.xyw.his00.utils.TimeUtils.LocalDateTimeRevertStringUtil;
import com.xyw.his00.vo.C_pay;
import com.xyw.his00.vo.D_pay;
import com.xyw.his00.vo.PatientCheck;
import com.xyw.his00.vo.PatientDisposal;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/disposalRequest/")
public class DisposalRequestController {
    @Resource
    private DisposalRequestMapper disposalRequestMapper;

    //医生诊疗：新增处置申请可以单个增加可以批量增加
    @Transactional
    @OptionLog
    @PostMapping("insertDisposalRequest")
    public ResponseData insertDisposalRequest(
            @RequestBody DisposalRequestDTO[] disposalRequestDTOs
    ) {
        System.out.println("批量插入检查申请执行成功");
        if (disposalRequestDTOs.length == 0) {
            return ResponseData.FAIL;
        } else {
            DisposalRequest[] disposalRequests = DisposalRequestDTO.revert(disposalRequestDTOs);
            for (int i = 0; i < disposalRequests.length; i++) {
                disposalRequestMapper.insert(disposalRequests[i]);
            }
            return  ResponseData.SUCCESS;
        }
    }


    //挂号收费员：搜索未交费的处置申请项目
    @RequestMapping("selectDisposalsNotPay")
    public List<D_pay> selectDisposalsNotPay(int registerId) {
        return disposalRequestMapper.selectDisposalsNotPay("已开立", registerId);
    }
    //搜索患者处置项目信息
    @RequestMapping("selectPatientDisposal")
    public List<PatientDisposal> selectPatientDisposal(int registerId){
        return disposalRequestMapper.selectPatientDisposal(registerId);
    }
    //根据医生id搜索患者处置项目信息
    @RequestMapping("selectPatientCheckByDoctorId")
    public List<PatientDisposal> selectPatientCheckByDoctorId(int doctorId){
        return disposalRequestMapper.selectPatientDisposalByDoctorId(doctorId);
    }
}
